﻿#region Apache License
/* 
   Copyright 2011 Jorge Teixeira

   Licensed under the Apache License, Version 2.0 (the "License");
   you may not use this file except in compliance with the License.
   You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.
*/
#endregion

using System;

namespace AdHoc.Wavesque
{
    /// <summary>
    /// Base class for waveforms.
    /// </summary>
    public abstract class Esque
    {
        /// <summary>
        /// Value to use on position increases.
        /// </summary>
        public double Step { get; protected set; }

        /// <summary>
        /// Amplitude of the oscillation.
        /// </summary>
        public double Amplitude { get; protected set; }

        /// <summary>
        /// Frequency of the oscillation (in Hz).
        /// </summary>
        public double Frequency { get; protected set; }

        /// <summary>
        /// Phase of the oscillation (in radians).
        /// </summary>
        public double Phase { get; protected set; }

        /// <summary>
        /// Gets a value indicating whether this instance is synchronized.
        /// </summary>
        /// <value>
        /// True if this instance is synchronized.
        /// </value>
        public virtual bool IsSynchronized { get { return false; } }

        /// <summary>
        /// Calculates a given number of points of a waveform for a given initial position.
        /// </summary>
        /// <param name="numberPoints">Number of points to compute.</param>
        /// <param name="x">Abscissae.</param>
        /// <param name="y">Ordinates.</param>
        /// <param name="x0">Initial position.</param>
        public abstract void GetValues(uint numberPoints, out double[] x, out double[] y, double x0);

        /// <summary>
        /// Calculates a given number of points of a waveform.
        /// </summary>
        /// <param name="numberPoints">Number of points to compute.</param>
        /// <param name="x">Abscissae.</param>
        /// <param name="y">Ordinates.</param>
        public void GetValues(uint numberPoints, out double[] x, out double[] y)
        {
            GetValues(numberPoints, out x, out y, 0.0);
        }

        /// <summary>
        /// Calculates a default number of points of a waveform.
        /// </summary>
        /// <param name="x">Abscissae.</param>
        /// <param name="y">Ordinates.</param>
        public void GetValues(out double[] x, out double[] y)
        {
            GetValues(EsqueHelpers.GetNumberOfPointsDefault(Frequency, Step), out x, out y, 0.0);
        }

        /// <summary>
        /// Calculates a default number of points of a waveform for a given initial position.
        /// </summary>
        /// <param name="x">Abscissae.</param>
        /// <param name="y">Ordinates.</param>
        /// <param name="x0">Initial position.</param>
        public void GetValues(out double[] x, out double[] y, double x0)
        {
            GetValues(EsqueHelpers.GetNumberOfPointsDefault(Frequency, Step), out x, out y, x0);
        }
    }
}
